define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'member/idcard/index' + location.search,
                    add_url: 'member/idcard/add',
                    edit_url: 'member/idcard/edit',
                    del_url: 'member/idcard/del',
                    multi_url: 'member/idcard/multi',
                    table: 'idcard',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'user_id',
                sortName: 'user_id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'users.uuid', title: __('Users.uuid')},
                        {field: 'users.phone', title: __('Users.phone')},
                        {field: 'users.truename', title: __('Users.truename')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'positive', title: __('Positive'), formatter: Table.api.formatter.image, events: Table.api.events.img},
                        {field: 'national_emblem', title: __('National_emblem'), formatter: Table.api.formatter.image, events: Table.api.events.img},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'admin_id', title: __('Admin_id')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange'},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table, buttons: [
                                {name: 'agree',
                                    text: '同意',
                                    title: '同意',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary  btn-dialog',
                                    url: 'member/Idcard/agree',
                                    success:function(data, ret){
                                        $(".btn-refresh").trigger("click");//刷新当前页面的数据
                                    }
                                },
                                {
                                    //拒绝用户提现
                                    name: 'refuse',
                                    text: '拒绝',
                                    title: '拒绝',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary  btn-dialog',
                                    url: 'member/Idcard/refuse'
                                },
                            ],events: Table.api.events.operate, formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                if(row.status == 2){
                                    return '已驳回';
                                }
                                if(row.status == 1){
                                    return '已通过';
                                }
                                var table = $(that.table).clone(true);
                                $(table).data("operate-edit", null);
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});